package cn.itcast.service.impl;

import cn.itcast.dao.MemberDao;
import cn.itcast.dao.OrderDao;
import cn.itcast.pojo.Order;
import cn.itcast.service.ReportService;
import cn.itcast.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;

    //查询运营数据
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        /*          reportDate:null,
                    todayNewMember :0,
                    totalMember :0,
                    thisWeekNewMember :0,
                    thisMonthNewMember :0,
                    todayOrderNumber :0,
                    todayVisitsNumber :0,
                    thisWeekOrderNumber :0,
                    thisWeekVisitsNumber :0,
                    thisMonthOrderNumber :0,
                    thisMonthVisitsNumber :0,
                    hotSetmeal :[
                        {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
                        {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}
                    ]*/
        Map<String, Object> map = new HashMap<>();
        //当前日期
        String today = DateUtils.parseDate2String(new Date());
        //周一
        String mondy = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        //本月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        //本日会员数
        Integer todayNewMember = memberDao.findTodayNewMember(today);
        //总会员数
        Integer totalMember = memberDao.totalMember();
        //本周会员数
        Integer thisWeekNewMember = memberDao.findAfterNewMember(mondy);
        //本月会员数
        Integer thisMonthNewMember = memberDao.findAfterNewMember(firstDay4ThisMonth);
        //今日预约数
        Integer todayOrderNumber = orderDao.findTodayNewOrder(today);
        //本周预约数
        Integer thisWeekOrderNumber = orderDao.findAfterNewOrder(mondy);
        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findAfterNewOrder(firstDay4ThisMonth);
        // 今日到诊数
        Integer todayVisitsNumber = orderDao.findTodayVisitsNumber(today);
        //本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findAfterVisitsNumber(mondy);
        //本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findAfterVisitsNumber(firstDay4ThisMonth);
        //热门套餐
        List<Map> hotSetmeal =orderDao.findHotSetmeal();

        map.put("reportDate",today);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }


}
